using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ScoreCanvasControl : MonoBehaviour
{
    Dictionary<string, Sprite> sprites;
    public Image medal;
    public TMPro.TMP_Text text;
    
    public int SilverScore
    {
        get { return silverScore; }
        set { silverScore = value; }
    }
    [SerializeField]
    private int silverScore;
    public int GoldScore
    {
        get
        {
            return goldScore;
        }
        set
        {
            goldScore = Mathf.Clamp(value, SilverScore, 10000);
        }
    }
    [SerializeField]
    private int goldScore;
    private void Start()
    {
        sprites = new Dictionary<string, Sprite>();
        AssetBundle ab = ABManger.LoadFromFile("ground");
        Sprite[] allSprites=ab.LoadAllAssets<Sprite>();
        foreach(Sprite sprite in allSprites)
        {
            
            if (sprite.name.Equals("gold") || sprite.name.Equals("silver") || sprite.name.Equals("copper"))
            {
                sprites.Add(sprite.name, sprite);
            }
        }
        
        ABManger.UnLoad(ab, false,out ab);
        int score = ScoreMangger.Instance.MaxScore;
        text.text=score.ToString();
        if (score == 0)
        {
            medal.sprite = null;
            medal.color = new Color(0f, 0f, 0f, 0f);
        }
        else if (score < SilverScore)
        {
            medal.sprite = sprites["copper"];
        }else if (score < GoldScore)
        {
            medal.sprite = sprites["silver"];
        }
        else
        {
            medal.sprite = sprites["gold"];
        }
        Debug.Log(SilverScore);
    }
}
